<?php

require_once("conn.php");
$sql = "SELECT * FROM t_product WHERE size = 0";
$db = new DBC();
$data = $db->fetchData($sql);
foreach ($data as $row) {
    $url = $row['url'];
    echo "<br>";
    echo "url=" . $url . "<br>";

    $str = "../update/" . substr($url, 23, strlen($url));
    echo "<br>str=" . $str;
    if (file_exists($str)) {
        $size = intval(filesize($str) / 1024 / 1024);
        echo " size = " . $size;
        $sql = "UPDATE t_product SET size = " . $size . " WHERE productid = " . $row['productid'];
        echo "<br>update sql = " . $sql;
        $db->execute($sql);
    }
    /*  $fp = fopen($url, "r");
      if ($fp) {
      $a_array = get_headers($url, true);
      $size = intval(round($a_array['Content-Length'] / (1024 * 1000), 3));
      $sql = "UPDATE size = ".$size." WHERE productid = ".$row['productid'];
      $db->execute($sql);
      echo "<br>sql=".$sql."<br>";
      fclose($fp);

      } else {
      echo $url . " 文件不存在！";
      }

     */
}
?>
